package com.lsa.tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class SplitDecorate {
	static String delims = "[\\[,\\]]"; 
	static String openDecorator = "\"";
	static String closeDecorator = "\"";
	
	public static void main(String[] args) throws IOException {
		InputStream in = ToArraysAsList.class.getResourceAsStream("SplitDecorate.txt");
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

		String line = null;
		boolean isFirst = true;
		
		StringBuilder result = new StringBuilder();
		
		while((line = br.readLine()) != null) {
			line = normalize(line);
			String[] parts = line.split(delims);
			for (String p : parts) {
				if (!p.isEmpty()) {
					result.append(String.format("%s%s%s,", openDecorator, p, closeDecorator));
				}
			}
			isFirst = false;
		}
		System.out.println(result.toString());
	}
	
	private static String normalize(String s){
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if (!Character.isWhitespace(c)) {
				sb.append(c);
			}
		}
		return sb.toString();
	}
}
